import api from "./api";
import http from "../http";

async function isLoggedIn() {
  try {
    const resp = await fetch(api.loggedInUser, {
      redirect: "error",
    });
    const data = await resp.json();
    return resp.status === 200 && data;
  } catch (error) {
    console.error("Error getting loggedIn userinfo:", error);
    return false;
  }
}

async function getLoggedInUser() {
  const resp = await http.get(api.loggedInUser);
  return resp.data;
}

function ruoyiLogin() {
  window.location.assign("/login");
}

function ruoyiLogout() {
  window.location.assign("/logout");
}

export { isLoggedIn, getLoggedInUser, ruoyiLogin, ruoyiLogout };
